AJAX (Asyncronous Javascript and XML) seems to be the latest craze in the online development world. Everyone's trying to incorporate it into their web applications. Luckily, the result is, in general, better than what we got when the "scroll" tag was in vogue, and with help from Fins, almost as easy to produce. The catch is that except for very simple applications, you're going to have to learn a little DOM and some JavaScript, but it's totally manageable. Dojo: a cross browser application toolkit We've decided to recommend the use of the wonderful http://www.dojotoolkit.org toolkit for your AJAX enabled Fins applications. Its proficiencies go far beyond just AJAX, and includes features such as client side implimentations of crypto algorithms and client side persistent storage. It's a little complicated, mostly due to the vast scope of what they're trying to accomplish, but after a little bit of time, you'll be getting your Dojo Mojo on (sorry, couldn't resist!) At the moment, we're not bundling Dojo, but our AJAX support macros assume a copy of Dojo installed in your app's /static/javascripts directory. AJAX Support Macros Fins includes some macros that make it easier to perform some simple AJAX operations. Things like asyncronous form submission, and asyncronous link actions. Details of how to use these macros are available on the modref for http://hww3.riverweb.com/dist/Fins/modref/ex/predef_3A_3A/Fins/Helpers/Macros/JavaScript.html. See the SmugMug sample app for a quick example of how to use the AJAX macros. JSON and JSON-RPC: JavaScript friendly data interchange http://www.json.org is a lightweight data interchange format optimized for use with JavaScript applications. You can easily encode your native Pike data to JSON and send it to a waiting browser for use more quickly and easily than other formats such as XML. Additionally, JSON-RPC allows you to make cross-application method calls that are easier to produce than SOAP or even XMLRPC. Fins includes a module, called Tools.JSON, that allows you to serialize native Pike data to a JSON format string, and conversely deserialize a JSON string into native Pike datatypes. These methods allow you to easily send and receive data in a format that JavaScript enabled browsers can easily digest. Additionally, Fins includes some tools for generating and decoding JSON-RPC calls, both in Tools.JSON and in Fins.JSONRPCController, which will allow you to create remotely callable functions quickly and easily.
> mapping m = (["foo": 1, "bar": "gazonk"]); > string s = Tools.JSON.serialize(m); > s; (1) Result: "{"bar":"gazonk","foo":1}" > Tools.JSON.deserialize(s); (2) Result: ([ /* 2 elements */ "bar": "gazonk", "foo": 1 ])
var app_global = this; // stolen shamelessly from dojo function app_undef(identifier) { if(!app_global) app_global = window; return (typeof app_global[identifier] == "undefined"); }
if(app_undef("dojo")) alert("Dojo isn't available!");